package domain.model.project;

import shared.model.ValueObject;

/**
 * @author Gregory Boissinot
 */
public enum ProjectStatus implements ValueObject<ProjectStatus> {

    OPEN(1, "OPEN"), CLOSED(2, "CLOSED");

    private int id;

    private String label;

    private ProjectStatus(final int id, final String label) {
        this.id = id;
        this.label = label;
    }

    public int getId() {
        return id;
    }

    public String getLabel() {
        return label;
    }

    @Override
    public boolean sameValueAs(ProjectStatus projectStatus) {
        return this.getId() == projectStatus.getId();
    }

    public static ProjectStatus get(String label) {

        if (label == null) {
            throw new IllegalArgumentException("A Project status label is required.");
        }

        final ProjectStatus[] allProjectStatus = ProjectStatus.values();
        for (ProjectStatus projectStatus : allProjectStatus) {
            if (projectStatus.getLabel().equalsIgnoreCase(label)) {
                return projectStatus;
            }
        }

        throw new IllegalArgumentException("No valid label for the ProjectStatus.");
    }

    public boolean isOpen() {
        return this.id == OPEN.getId();
    }

    public boolean isClose() {
        return this.id == CLOSED.getId();
    }


}
